package com.hunt.framework.manager;

import java.util.TimerTask;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @program: hunt-lx
 * @description: 异步任务管理器 ,采用饿汉式单例模式
 * @author: Lx
 * @create: 2019-02-01 22:08
 **/
public class AsyncManager
{
    /**
     * 操作延迟10毫秒
     */
    private final int OPERATE_DELAY_TIME = 10;

    /**
     * 异步操作任务调度线程池
     */
    private ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(5);

    private static AsyncManager manager = new AsyncManager();

    public static AsyncManager me()
    {
        return manager;
    }

    /**
     * 执行任务
     *
     * @param task
     */
    public void execute(TimerTask task)
    {
        executor.schedule(task, OPERATE_DELAY_TIME, TimeUnit.MILLISECONDS);
    }
}
